import { Button, message } from 'antd'

import PubSub from 'pubsub-js'
import { RemoveOptions } from '@/types'
import { useDel } from '@/api/query'

export default function Remove(data: RemoveOptions) {
  const { mutate } = useDel(data.path)
  // 删除用户
  const delUser = (id: string) => {
    mutate(id, {
      onSuccess: () => {
        PubSub.emit('changeData')
        message.success('删除成功')
      },
      onError: (err) => {
        message.error('删除失败')
        console.log(err)
      }
    })
  }
  return (
    <Button onClick={() => delUser(data.id)} type="primary" danger>
      删除
    </Button>
  )
}
